package bigdata.api.push.asticketbiz;

import bigdata.api.login.LoginConvert;
import com.google.gson.reflect.TypeToken;
import common.utils.gsonutil.GsonUtil;
import datacenterbizapiexternal.asticketbiz.domain.entity.AsTicketSaleInfo;
import datacenterbizapiexternal.asticketbiz.domain.entity.AsTicketTouristOriginArea;
import datacenterbizapiexternal.asticketbiz.domain.request.push.AsPushRequest;
import datacenterbizapiexternal.asticketbiz.service.AsTicketSaleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pub.user.domain.LoginResult;

import java.util.Date;

/**
 * 描述:asticketbiz
 *
 * @author 002465
 * @created 2017/5/21 23:55
 * @return ${return_type}
 * @since v1.0.0
 * ${tags}
 */
@Controller
@RequestMapping("/pushAsticketbiz")
public class PushAsticketbizCtrl {
    @Autowired
    private AsTicketSaleInfoService asTicketSaleInfoService;

    @RequestMapping(value = "/pushAsTicketSaleInfo")
    @ResponseBody
    public String pushAsTicketSaleInfo(@RequestBody String json) {
        AsPushRequest<AsTicketSaleInfo> request = GsonUtil
                .create().fromJson(json,
                        new TypeToken<AsPushRequest<AsTicketSaleInfo>>() {
                        }.getType());
        if(request!=null&&request.getSuccess()){
            Date saveDate = asTicketSaleInfoService.saveOrUpdateAsTicketSaleInfo(request.getList());
        }
        LoginResult loginResult = new LoginResult();

        return LoginConvert.toJson(loginResult);
    }

    @RequestMapping(value = "/pushAsTicketTouristOriginArea")
    @ResponseBody
    public String pushAsTicketTouristOriginArea(@RequestBody String json) {
        AsPushRequest<AsTicketTouristOriginArea> request = GsonUtil
                .create().fromJson(json,
                        new TypeToken<AsPushRequest<AsTicketTouristOriginArea>>() {
                        }.getType());
        if(request!=null&&request.getSuccess()){
            Date saveDate = asTicketSaleInfoService.saveOrUpdateAsTicketTouristOriginArea(request.getList());
        }
        LoginResult loginResult = new LoginResult();

        return LoginConvert.toJson(loginResult);
    }
}
